package com.zhouxiaoge.security.validate.code.sms;

import com.zhouxiaoge.security.validate.code.ValidateCode;
import com.zhouxiaoge.security.validate.code.impl.AbstractValidateCodeProcessor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.ServletRequestBindingException;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.context.request.ServletWebRequest;

/**
 * 作者：周小哥
 * 时间：2018-10-16 09:44
 */
@Component("smsCodeProcessor")
public class SmsCodeProcessor<C extends ValidateCode> extends AbstractValidateCodeProcessor<C> {

    @Autowired
    private SmsCodeSender smsCodeSender;

    @Override
    protected void send(ServletWebRequest request, ValidateCode validateCode) throws ServletRequestBindingException {
        String mobile = ServletRequestUtils.getRequiredStringParameter(request.getRequest(), request.getParameter("mobile"));
        smsCodeSender.send(mobile, validateCode.getCode());
    }
}
